﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Web;

namespace Chisholm.Windows.Live.Security
{
    /// <summary>
    /// This implements the security provider and returns a users Windows Live account based on their
    /// given SharePoint credentials
    /// </summary>
    public class SharePointEmailSecurity : ISecurityProvider
    {
        /// <summary>
        /// This searches the given security provider, and returns the Windows Live ID for the 
        /// given identity credentials passed through
        /// </summary>
        /// <param name="credentials">An object containing the particular identity credentials</param>
        /// <param name="configuration">A configuration string (if required) for the provider</param>
        /// <param name="windowslivedomain">The Windows Live e-mail domain (e.g. my.uni.edu.au)</param>
        /// <returns>The Windows Live ID for the given credentials</returns>
        public string GetWindowsLiveID(object credentials, string configuration, string windowslivedomain)
        {
            // Check to ensure the passed through object is a valid SPContext
            if (credentials != null && credentials is SPContext)
            {
                // A valid context has been passed through so use it
                return SPContext.Current.Web.CurrentUser.Email;
            }
            else
                return String.Empty;
        }
    }
}
